package org.tang;

import com.alibaba.fastjson.JSON;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.tang.utils.SRSUtils;

import java.util.List;

@RestController
public class CallBackController {

    @GetMapping("/kickoff")
    //剔除客户端
    public String kickoff(String client){
        SRSUtils.kickoffClients(client);
        return "剔除成功";
    }

    @GetMapping("/queryAll")
    //查询所有被拉黑的客户端的ip
    public List<String> queryAll(){
        return SRSUtils.BLACK_LIST;
    }

    @GetMapping("/recovery")
    public String recovery(String client){
        return SRSUtils.recoveryClient(client);
    }

//    一下两个接口分别就收推送流 接受流   开始播放 结束播放的回调
    @PostMapping("/api/v1/streams")
    public String get(@RequestBody SRS srs){
        if(SRSUtils.BLACK_LIST.contains(srs.getIp())){
            return "{\"code\": 403}";
        }
        String action = srs.getAction();
        System.out.println("回调事件"+action);
        System.out.println(JSON.toJSONString(srs));
        return "{\"code\": 0}";
    }

    @PostMapping("/api/v1/sessions")
    public String two(@RequestBody SRS srs){
        String action = srs.getAction();
        System.out.println("回调事件"+action);
        System.out.println(JSON.toJSONString(srs));
        return "{\"code\": 0}";
    }
}
